#include <iostream>
#include <limits.h> 

using namespace std;

float a[100];
void two(int i, int j, float &fmin2, float &fmin1);
float second(int n) {
    float min2, min1 = INT_MAX;
    two(0, n - 1, min2, min1);
    return min2;
}

void two(int i, int j, float &fmin2, float &fmin1) {
    float lmin2, lmin1, rmin2, rmin1;
    int mid;

    if (i == j) {
        fmin1 = fmin2 = a[i];
    } else if ((j - i) == 1) {
        if (a[i] < a[j]) {
            fmin1 = a[i];
            fmin2 = a[j];
        } else {
            fmin1 = a[j];
            fmin2 = a[i];
        }
    } else {
        mid = (i + j) / 2;
        two(i, mid, lmin2, lmin1);
        two(mid + 1, j, rmin2, rmin1);

        if (lmin1 < rmin1) {
            if (lmin2 < rmin1) {
                fmin1 = lmin1;
                fmin2 = lmin2;
            } else {
                fmin1 = lmin1;
                fmin2 = min(rmin2, lmin2); 
            }
        } else {
            if (rmin2 < lmin1) {
                fmin1 = rmin1;
                fmin2 = min(rmin2, lmin1); 
            } else {
                fmin1 = rmin1;
                fmin2 = min(rmin2, lmin2);
            }
        }
    }
}

int main() {
    int n;
    cout << "Enter the number of elements: ";
    cin >> n;

    cout << "Enter the elements: ";
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }

    float min2 = second(n);
    cout << "The second minimum element is: " << min2 << endl;

    return 0;
}